package com.ruoyi.web.controller.system.api.cc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.User;
import com.ruoyi.system.api.service.ToolService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;

/**
 * @ClassName ToolController
 * @Description: 工具管理
 * @Author wlf
 * @Date 2020/3/3
 * @Version V1.0
 **/
@Api(tags="工具管理")
@Controller
@RequestMapping("/api/cc/tool")
public class ToolController extends BaseController {

    @Autowired
    ToolService toolService;

    private static final Logger log = LoggerFactory.getLogger(ToolController.class);
    /**
     * 获取工程师名下工具接口
     * @methodName: getToolByFse
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: wlf
     * @date: 2020/3/2 11:09
     **/
    @PostMapping("/getToolByFse")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取工程师名下工具接口", httpMethod = "POST", notes = "获取工程师名下工具接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "enginnerId", value = "工程师ID", required = true, dataType="String") ,
            @ApiImplicitParam(name = "status", value = "工具状态", dataType="String"),
            @ApiImplicitParam(name = "toolNo", value = "工具号", dataType="String"),
            @ApiImplicitParam(name = "toolNname", value = "工具名称", dataType="String")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getToolByFse(@RequestBody Map<String, String> params){
        try {
            return toolService.getToolByFse(params);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 获取工具库可借用的工具接口
     * @methodName: getBorrowTool
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: wlf
     * @date: 2020/3/2 11:09
     **/
    @PostMapping(value = "/getBorrowTool")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取工具库可借用的工具接口", httpMethod = "POST", notes = "获取工具库可借用的工具接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "enginnerId", value = "工程师ID", required = true, dataType="String") ,
            @ApiImplicitParam(name = "status", value = "工具状态", dataType="String"),
            @ApiImplicitParam(name = "toolNo", value = "工具号", dataType="String"),
            @ApiImplicitParam(name = "toolNname", value = "工具名称", dataType="String")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getBorrowTool(@RequestBody Map<String, String> params){
        try {
            return toolService.getBorrowTool(params);
        }catch (Exception e){
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 工具收货(支持批量，接口支持JSON)
     * @methodName: toolReceiving
     * @description: TODO
     * @param params
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: wlf
     * @date: 2020/3/2 11:09
     **/
    @Log(title = "工具收货", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/toolReceiving")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "工具收货", httpMethod = "POST", notes = "工具收货")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "enginnerId", value = "工程师ID", required = true, dataType="String") ,
            @ApiImplicitParam(name = "toolInfo", value = "工具信息", required = true, dataType="String")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> toolReceiving(@RequestBody Map<String, Object> params){
        try {
            return toolService.toolReceiving(params);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 工具还货
     * @methodName: toolReturnLib
     * @description: TODO
     * @param params
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: wlf
     * @date: 2020/3/2 11:09
     **/
    @Log(title = "工具还货", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/toolReturnLib", produces = "application/json")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "工具还货", httpMethod = "POST", notes = "工具还货")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applyMain", value = "工具还货表单", required = true, dataType="String") ,
            @ApiImplicitParam(name = "applyTools", value = "归还工具数组", required = true, dataType="String")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> toolReturnLib(@RequestBody String params){
        try {
            return toolService.toolReturnLib(params);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 工具借用申请
     * @methodName: applyBorrowTool
     * @description: TODO
     * @param params
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: wlf
     * @date: 2020/3/2 11:09
     **/
    @Log(title = "工具借用申请", businessType = BusinessType.INSERT)
    @PostMapping(value = "/applyBorrowTool", produces = "application/json")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "工具借用申请", httpMethod = "POST", notes = "工具借用申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applyMain", value = "工具申请表单", required = true, dataType="String") ,
            @ApiImplicitParam(name = "applyTools", value = "申请工具数组", required = true, dataType="String")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> applyBorrowTool(@RequestBody String params){
        try {
            return toolService.applyBorrowTool(params);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
}
